package com.yunhe.abnormal.client;

import com.yunhe.abnormal.client.fallback.AuthorityFallbackFactory;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.authority.FirmDTO;
import com.yunhe.common.model.authority.Role;
import com.yunhe.common.model.authority.StationDTO;
import com.yunhe.common.model.authority.UserDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 权限Feign客户端
 * @author liuronglei
 */
@FeignClient(value = "ems-authority", fallbackFactory = AuthorityFallbackFactory.class)
public interface AuthorityClient {

    /**
     * 根据单位代码获得单位
     * @param id 单位ID
     */
    @RequestMapping(value = "/firms/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<FirmDTO>> getFirmById(@PathVariable("id") Long id);

    /**
     * 根据电站代码获得电站
     * @param code 电站代码
     */
    @RequestMapping(value = "/stations/byCode", method = RequestMethod.GET)
    ResponseEntity<ResultObject<StationDTO>> getStationByCode(@RequestParam("code") Long code);

    /**
     * 根据条件获得用户列表
     * @param id 用户Id
     */
    @RequestMapping(value = "/users/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<UserDTO>> getUserById(@PathVariable("id") Long id);

    /**
     * 根据单位ID获得电站列表
     * @param firmId 单位ID
     */
    @RequestMapping(value = "/stations/byFirm/{firmId}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<StationDTO>>> getStationByFirmId(@PathVariable("firmId") Long firmId);
    /**
     * 根据电站ID获得电站列表
     * @param id 单位ID
     */
    @RequestMapping(value = "/stations/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<StationDTO>> getStationById(@PathVariable("id") Long id);

    /**
     * 根据设备ID获得电站
     * @param deviceId 设备ID
     */
    @RequestMapping(value = "/stations/byDeviceId", method = RequestMethod.GET)
    ResponseEntity<ResultObject<StationDTO>> getStationByDeviceId(@RequestParam("deviceId") Long deviceId);

    /**
     * 根据用户ID获得其所属角色列表
     * @param id
     * @return
     */
    @RequestMapping(value = "/users/{id}/roles", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<Role>>> getRolesByUserId(@PathVariable("id") Long id);

    @RequestMapping(value = "/users/byStationId/related", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<UserDTO>>> getRelatedUserByStationId(@RequestParam("stationId") Long stationId);

    @RequestMapping(value = "/stations/timeZoneId", method = RequestMethod.GET)
    ResponseEntity<ResultObject<String>> getTimeZoneIdByStationId(@RequestParam("id") Long stationId);

    /**
     * 根据条件获得电站列表
     */
    @RequestMapping(value = "/stations", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<StationDTO>>> searchStation(@RequestParam("stationTypeId") Long stationTypeId);
}
